﻿@model Citi.GocAttributes.WebUI.Models.RuleModel
@section Menu
{
    @Html.Partial("~/Views/Menu/Rules.cshtml", new ViewDataDictionary())
}
<script type="text/javascript">
    function changeEditButton(buttonId, divId) {
        var button = $("#" + buttonId);
        var div = $("#" + divId);
        div.toggle();
        var divDetail = $("#" + divId + "Detail");
        divDetail.toggle();

        if (button.html().indexOf('Edit') >= 0)
            button.html('<i class="icon-remove"></i>&nbsp;&nbsp;&nbsp; Close');
        else
            button.html('<i class="icon-pencil"></i>&nbsp;&nbsp;&nbsp; Edit');
    }

    function showHideRuleCondition() {
        changeEditButton("linkRuleCondition", "ruleConditions");

        if ($("#ruleResults").is(":visible"))
            changeEditButton("linkRuleResult", "ruleResults");
    }

    function showHideRuleResult() {
        changeEditButton("linkRuleResult", "ruleResults");

        if ($("#ruleConditions").is(":visible"))
            changeEditButton("linkRuleCondition", "ruleConditions");
    }

    $(function () {
        @if (Request.QueryString["Details"] != null)
        {
            <text>
                $("#linkRuleResult").hide();
                $("#linkRuleCondition").hide();
            </text>
        }
    });
</script>
@using (Ajax.BeginForm("Form", "Rule", new { id = "ruleAjaxForm", name = "ruleAjaxForm" },
    new AjaxOptions { UpdateTargetId = "ruleList", OnComplete = "openCloseRuleDialog" }))
{
    @Html.ValidationSummary(true)
    <fieldset>
        <div id="divGocsId"></div>
        <div id="divRuleName">
            Name: &nbsp;&nbsp;
            @if (Request.QueryString["Details"] != null)
            {
                @Html.DisplayFor(model => model.Name)
            }
            else
            {
                @Html.EditorFor(model => model.Name)
            }
            @Html.ValidationMessageFor(model => model.Name)
       
            &nbsp;&nbsp;&nbsp;&nbsp;Order: &nbsp;&nbsp;
            @if (Request.QueryString["Details"] != null)
            {
                @Html.DisplayFor(model => model.Order)
            }
            else
            {
                @*@Html.EditorFor(model => model.Order)*@
                @Html.DropDownListFor(model => model.Order, (SelectList)ViewBag.Orders);
            }
            @Html.ValidationMessageFor(model => model.Order)
        </div>
        @if (Model != null)
        {
            @Html.HiddenFor(model => model.Id)
        }
        <fieldset id="fieldsetRuleCondition">
            <legend style="float: left;">Rule Conditions</legend><a href="#" id="linkRuleCondition"
                                                                    class="btn" style="float: right; margin-top: -50px;" onclick="showHideRuleCondition();">
                                                                     <i class="icon-pencil"></i>&nbsp;&nbsp;&nbsp; Edit </a>
            <div id="ruleConditionsDetail">
                @Html.Partial("~/Views/RuleCondition/List.cshtml", Model != null ? Model.RuleConditions : null)
            </div>
            <div id="ruleConditions" style="display: none;">
                @Html.Partial("~/Views/RuleCondition/Form.cshtml", Model != null ? Model.RuleConditions : null)
            </div>
        </fieldset>
        <fieldset>
            <legend style="float: left;">Rule Results</legend><a href="#" id="linkRuleResult"
                                                                 class="btn" style="float: right; margin-top: -50px;" onclick="showHideRuleResult();">
                                                                  <i class="icon-pencil"></i>&nbsp;&nbsp;&nbsp; Edit </a>
            <div id="ruleResultsDetail">
                @Html.Partial("~/Views/RuleResult/List.cshtml", Model != null ? Model.LastRuleResults : null)
            </div>
            <div id="ruleResults" style="display: none;">
                @Html.Action("Form", "RuleResult", new { models = Model != null ? Model.LastRuleResults : null })
            </div>
        </fieldset>
    </fieldset>
    <input type="submit" id="submitRuleForm" class="hide" />
}
